package com.coderman.infosys.auth.adapter.controller.user;

import com.coderman.infosys.auth.adapter.controller.BaseController;
import com.coderman.infosys.auth.adapter.convert.UserGroupConverter;
import com.coderman.infosys.auth.domain.bo.user.UserGroupBO;
import com.coderman.infosys.auth.domain.gataway.UserRoleQueryGataway;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import com.coderman.infosys.plat.auth.common.vo.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coderman.infosys.auth.adapter.vo.user.UserGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


/**
* @Description:控制层
* @Author:
* @CreateTime:2022-01-04 15:27:39
* @version v1.0
*/
@RestController
public class UserGroupQueryController extends BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(UserGroupQueryController.class);

	@Autowired
	private UserRoleQueryGataway userRoleQueryGataway;

	/**
	 *
	 * @Description 分页获取用户组信息
	 * @param pageVO
	 * @return PageVO<UserGroupVO>
	 */
	@RequestMapping(value = "/usergroup/pagelist")
	public ResultDataDto<PageVO> getPageList(@RequestParam(value = "pageVO", required = true) PageVO pageVO ){
		PageBO pageBO = pageVO.convertToBO();
		List<UserGroupBO> userGroupBOList = userRoleQueryGataway.getUserGroupPageList(pageBO);
		return ResultDataDto.success(pageVO.initData(UserGroupConverter.INSTANCE.boList2voList(userGroupBOList),pageBO.getTotalRows()));
	}


	/**
	 *
	 * @Description 根据code或者名称搜索用户组信息
	 * @param search
	 * @return List<UserGroupDTO>
	 */
	@RequestMapping(value = "/usergroup/search")
	public ResultDataDto<List<UserGroupVO>> search(@RequestParam(value = "search", required = true) String search){
		List<UserGroupBO>  userGroupBOList = userRoleQueryGataway.searchUserGroup(search);
		return ResultDataDto.success(UserGroupConverter.INSTANCE.boList2voList(userGroupBOList));
	}
}
